package com.ktjy.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 增强类
 */
@Component("loggerAspect")
@Aspect
public class LoggerAspect {
    Logger logger= LoggerFactory.getLogger(LoggerAspect.class);

    @Before(value = "execution(* com.ktjy.service..*.*(..))")
    public void before(JoinPoint joinPoint){
        logger.info("方法开始执行{},{},{}",
                joinPoint.getTarget(),
                joinPoint.getSignature().getName(),
                joinPoint.getArgs());
    }

    @AfterReturning(value = "execution(* com.ktjy.service..*.*(..))",returning = "result")
    public void after(JoinPoint joinPoint,Object result){
        logger.info("方法结束执行,{},{},{},{}",joinPoint.getTarget(),
                joinPoint.getSignature().getName(),
                joinPoint.getArgs(),
                result);
    }
}
